package com.lagou.common;

import com.alibaba.fastjson.JSON;

import java.util.UUID;

public class JSONSerializer implements Serializer{

    public byte[] serialize(Object object) {

        return JSON.toJSONBytes(object);

    }



    public <T> T deserialize(Class<T> clazz, byte[] bytes) {

        return JSON.parseObject(bytes, clazz);

    }

    public static void main(String[] args) {
        RpcRequest rpcRequest = new RpcRequest();
        rpcRequest.setRequestId(UUID.randomUUID().toString());
        rpcRequest.setClassName("aa");
        rpcRequest.setMethodName("bb");
        rpcRequest.setParameters(args);
        rpcRequest.setParameterTypes(new Class[]{String.class});
        JSONSerializer jsonSerializer = new JSONSerializer();
        byte[] serialize = jsonSerializer.serialize(rpcRequest);
        RpcRequest deserialize = jsonSerializer.deserialize(RpcRequest.class, serialize);
        System.out.println(deserialize );
    }

}